﻿<%@ Page Language="C#" %>
<%@ Import Namespace="IRL.Utilities" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">    
    public const int CURRENT_MODULE = 52;
    
    static string sortFld;
    
    protected void Page_Load(object src, EventArgs e)
    {
        Security SysAcc = new Security(CURRENT_MODULE);
        // check is authenticate
        SysAcc.Authenticate();
        // load reminder count        
        Mics.loadReminderCount(lblReminderCount);
                
        if (!Page.IsPostBack)
        {
            sortFld = "Company_Name";
            rebind();
        }
        // Remove ClientID Session
        if (Session["ClientID"] != null)
            Session.Remove("ClientID");
    }

    // bind to datagrid
    void rebind()
    {
        object connStr = ConfigurationSettings.AppSettings["sqlConn"];
		using(SqlConnection conn = new SqlConnection(connStr.ToString()))
		{
			SqlDataAdapter adapter = new SqlDataAdapter("SELECT [Company_ID], [Company_Name], [Sector], [Country] FROM [vw_Clients]", conn);
			DataSet ds = new DataSet();
			DataView dv;
			adapter.Fill(ds, "Clients");
			// Bind to Grid
			dv = ds.Tables[0].DefaultView;
			dv.Sort = sortFld;        
			grid1.DataSource = dv;
			grid1.DataBind();
		}
    }

    protected void grid1_SortCommand(object src, DataGridSortCommandEventArgs e)
    {
        string strOrder = "";

        if (sortFld == e.SortExpression)
        {
            strOrder = " DESC";
        }
        sortFld = e.SortExpression + strOrder;
        rebind();
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="Description" content="Providing the tools and expertise needed to navigate in the emerging consumer markets of Indochina.">
    <meta name="keywords" content="Research in Indochina, Research Consultants in Indochina, Marketing Research in Indochina, Marketing Research Companies in Indochina, Marketing Consultants in Indochina Research in Vietnam, Research Consultants in Vietnam, Marketing Research in Vietnam, Marketing Research Companies in Vietnam, Marketing Consultants in Vietnam Research in Cambodia, Research Consultants in Cambodia, Marketing Research in Cambodia, Marketing Research Companies in Cambodia, Marketing Consultants in Cambodia Research in Laos, Research Consultants in Laos, Marketing Research in Laos, Marketing Research Companies in Laos, Marketing Consultants in Laos">
    <meta name="robots" content="all">

    <title>List of Clients</title>
    <link type="text/css" rel="stylesheet" href="css/style_1.css" />
    <script language="javascript" src="includes/menustructure.js"></script>

</head>

<body>
<table width="773" border="0" cellspacing="0" cellpadding="0" align="center">
	<tr>
		<td width="765" height="540" align="center" valign="top" style="border:solid 1px #10147e;" >
			<!-- header -->
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr bgcolor="#F4F4F9">
					<td colspan="3" align="right" style="padding:10px;">
						<b class="blueL">Client Management System</b>
					</td>
				</tr>
				<tr>
					<td class="wave_l">
						<table width="100%" border="0" cellpadding="0" cellspacing="0">
						      <tr class="menu">
							  	<td><a class="dropdown" onMouseOver="dropdownmenu(this, event, menu1,'160px')" onMouseOut="delayhidemenu()">Project Management</a></td>
							    <td><a href="listClients.aspx">Clients &amp; Contacts</a></td>
							  </tr>
						</table></td>
					<td><img src="images/wave_logo.jpg" width="107" height="83"></td>
					<td class="wave_r">
						<table width="100%" border="0" cellpadding="0" cellspacing="0">
						      <tr class="menu">
							  	<td><a href="ops_Proposals.aspx">Ops files</a></td>
							    <td align="center"><a class="dropdown" onMouseOver="dropdownmenu(this, event, menu2, '160px')" onMouseOut="delayhidemenu()">Reminders <asp:Literal ID="lblReminderCount" runat="server" /></a></td>
                                <td align="right"><a href="javascript:window.close();">Close</a></td>
							  </tr>
						</table></td>
				</tr>
				<tr>
					<td colspan="3" style="padding:0 20px;">
						<div style="background-color:#bcb3d5; padding:5px 10px;">
							<span style="float:right">
								<a class="blue" href="SaveClient.aspx">Add New Client*</a></span>
							<span class="pathmap">
								<a href="default.aspx">CPanel</a> :: Clients
								</span>
						</div>
						
					</td>
				</tr>
				
			</table>
			
			<!-- body -->
			<table border="0" width="100%" cellspacing="0" cellpadding="0">
				<tr>
					<td align="center" style="padding:20px;">
                        <table class="data" width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                                <td>
                                    <!-- data row  style="overflow-x:auto; width:560px"-->
                                    <div>
                                        <form id="frmClients" runat="server">
                                            <asp:DataGrid ID="grid1" Width="100%" runat="server" CellSpacing="1" CellPadding="4"
                                                BorderWidth="0" GridLines="none" AllowSorting="true" AutoGenerateColumns="false"
                                                OnSortCommand="grid1_SortCommand">
                                                <HeaderStyle BackColor="#BCB3D5" Font-Size="7.5pt" ForeColor="White" Font-Bold="True" />
                                                <AlternatingItemStyle BackColor="#EFEFEF" />
                                                <Columns>
                                                    <asp:TemplateColumn HeaderText="No">
                                                        <HeaderStyle Width="25px" />
                                                        <ItemTemplate>
                                                            <%# Container.ItemIndex+1%>
                                                        </ItemTemplate>
                                                    </asp:TemplateColumn>
                                                    <asp:TemplateColumn HeaderText="Client Name" SortExpression="Company_Name">
                                                        <HeaderStyle Width="360px" />
                                                        <ItemTemplate>
                                                            <a href="listContacts.aspx?cid=<%# DataBinder.Eval(Container.DataItem, "Company_ID") %>">
                                                                <%# DataBinder.Eval(Container.DataItem, "Company_Name") %>
                                                            </a>
                                                        </ItemTemplate>
                                                    </asp:TemplateColumn>
                                                    <asp:TemplateColumn HeaderText="Sector" SortExpression="Sector">
                                                        <HeaderStyle Width="100px" />
                                                        <ItemTemplate>
                                                            <%# DataBinder.Eval(Container.DataItem, "Sector").ToString()%>
                                                        </ItemTemplate>
                                                    </asp:TemplateColumn>
                                                    <asp:TemplateColumn HeaderText="Country" SortExpression="Country">
                                                        <HeaderStyle Width="100px" />
                                                        <ItemTemplate>
                                                            <%# DataBinder.Eval(Container.DataItem, "Country").ToString()%>
                                                        </ItemTemplate>
                                                    </asp:TemplateColumn>
                                                </Columns>
                                            </asp:DataGrid>
                                        </form>
                                    </div>
                                </td>
                            </tr>
                        </table>
					</td>
				</tr>
			</table>
			
		</td>
		
		<td width="6" class="rightShadow" valign="top">
			<img src="images/white.gif" width="6" height="6" /></td>
	</tr>
	
	<!-- bottom shadow -->
	<tr>
		<td height="6" class="bottomShadow">
			<img src="images/white.gif" width="6" height="6" /></td>
		
		<td width="6" height="6">
			<img src="images/shadow_corner.gif" width="6" height="6" /></td>
	</tr>
</table>

</body>
</html>
